package Test;

import java.util.concurrent.TimeUnit;

public class TestDemo11 {

    public static void main(String[] args) throws InterruptedException {
        Number number = new Number();
        for (int i = 0; i < 10; i++) {
            new Thread(()->{
                for (int j = 0; j < 1000; j++) {
                    number.add();
                }
            }).start();
        }
        TimeUnit.SECONDS.sleep(2);
        System.out.println(number.getNumber());
    }
}

class Number {
    int number;

    public int getNumber() {
        return number;
    }


    public synchronized void add() {
        number++;
    }
}
